<?php
session_start();
include("config.php");

$occam_copper_access_profile_query = mysql_query("SELECT * FROM access_profiles");
$occam_copper_dsl_profile_query = mysql_query("SELECT * FROM dsl_profiles");
$occam_ont_ip_query = mysql_query("SELECT * FROM ont_ip");
?>
<table width="100%" class="results">
	<tr><th>Copper Access Profile Management</th></tr>
	<tr><td style="text-align: left">
	<form>
		Access Profile Name:<input type="text" id="occam_copper_access_profile_name" value="" maxlength="15"></input><br/>
		Access Profile Description:<input type="text" id="occam_copper_access_profile_description" value="" maxlength="35"></input></br>
		<input type="button" value="Add" onClick="add_occam_copper_access_profile(this.form.occam_copper_access_profile_name.value, this.form.occam_copper_access_profile_description.value)"></input>
	</form>
	<hr/>
	</td></tr>
	<tr><td style="text-align: left">
	<div id="occam_copper_access_profile_results">
	<?php
		while ($row = mysql_fetch_array($occam_copper_access_profile_query)) {
			$profile_id = $row['profile_id'];
			$access_profile_name = $row['profile_name'];
			$access_profile_description = $row['profile_description'];
			echo "<form>";
			echo "<a href=\"#\" onclick=\"delete_occam_copper_access_profile('$profile_id', '$access_profile_name')\">delete</a>";
			echo "<input type=\"text\" value=\"$access_profile_name\" name=\"access_profile_name\"></input>";
			echo "<input type=\"text\" value=\"$access_profile_description\" name=\"access_profile_description\"></input>";
			echo "<input type=\"button\" onClick=\"update_occam_copper_access_profile('$profile_id', this.form.access_profile_name.value, this.form.access_profile_description.value)\" value=\"Update\"></input><br/>";
			echo "</form>";
		}
	?>
	</div>
	</td></tr>
</table>
<br/>
<table width="100%" class="results">
	<tr><th>Copper DSL Profile Management</th></tr>
	<tr><td style="text-align: left">
	<form>
		DSL Profile Name:<input type="text" id="occam_copper_dsl_profile_name" value="" maxlength="12"></input>
		<input type="button" value="Add" onClick="add_occam_copper_dsl_profile(this.form.occam_copper_dsl_profile_name.value)"></input>
	</form>
	<hr/>
	</td></tr>
	<tr><td style="text-align: left">
	<div id="occam_copper_dsl_profile_results">
	<?php
		while ($row = mysql_fetch_array($occam_copper_dsl_profile_query)) {
			$dsl_profile_id = $row['dsl_profile_id'];
			$dsl_profile_name = $row['dsl_profile_name'];
			echo "<form>";
			echo "<a href=\"#\" onclick=\"delete_occam_copper_dsl_profile('$dsl_profile_id','$dsl_profile_name')\">delete</a>";
			echo "<input type=\"text\" value=\"$dsl_profile_name\" name=\"dsl_profile_name\"></input>";
			echo "<input type=\"button\" onClick=\"update_occam_copper_dsl_profile('$dsl_profile_id', this.form.dsl_profile_name.value)\" value=\"Update\"></input><br/>";
			echo "</form>";
		}
	?>
	</div>
	</td></tr>
</table>
<br/>
<table width="100%" class="results">
	<tr><th>ONT IP Addresses</th></tr>
	<tr><td style="text-align: left">
	<form>
		<select name="occam_fiber_blade_ip">
			<?php
			//  Grab all of the fiber blades from the database
			$fiber_blade_query = mysql_query("SELECT * FROM devices WHERE device_type = '6312' OR device_type = '6316'");
			while ($row = mysql_fetch_array($fiber_blade_query)) {
				$blade_ip = $row['device_ip'];
				//  Check to see if the blade already has IP's assigned to it
				$query = mysql_query("SELECT * FROM ont_ip WHERE blade_ip = '$blade_ip'");
				if (mysql_num_rows($query) == 0) {
					echo "<option value=\"$blade_ip\">$blade_ip</option>";
				} else {
					//Blade already has IP's assigned to it
				}
			}
			?>
		</select>
		<input type="text" id="occam_fiber_ont_start_ip" name="occam_fiber_ont_start_ip"></input>
		<input type="button" value="Add" onClick="add_occam_fiber_ont_start_ip(this.form.occam_fiber_blade_ip.value, this.form.occam_fiber_ont_start_ip.value)"></input>
	</form>
	<hr/>
	<div id="occam_ont_ip_start">
	<?php
		while ($row = mysql_fetch_array($occam_ont_ip_query)) {
			$blade_ip = $row['blade_ip'];
			$ip_start = $row['ip_start'];
			echo "<form>";
			echo "<a href=\"#\" onClick=\"delete_table_row('ont_ip', 'blade_ip', '$blade_ip')\">delete</a> $blade_ip";
			echo "<input type=\"text\" value=\"$ip_start\" name=\"start_ip\"></input>";
			echo "<input type=\"button\" value=\"Update\" onClick=\"update_occam_ont_start_ip('$blade_ip', this.form.start_ip.value)\"></input><br/>";
			echo "</form>";
		}
	?>	
	</div>
</table>
<script type="text/javascript">

function add_occam_copper_access_profile(name, description) {
        var url='pages/query.php?';
        url=url+'&cmd=add_occam_copper_access_profile';
        url=url+'&name='+name;
        url=url+'&description='+escape(description);
        url=url+'&sid='+Math.random();
        
        //Send the data to the query.php script to update the DB
        var myRequest = new Request({
                url: url, 
                onSuccess: function(response) {
                                //TODO:  Append the new profile to the results list
                                //alert(response);
                } 
        }).send();
}

function update_occam_copper_access_profile(profile_id, name, description) {
        var url='pages/query.php?';
        url=url+'&cmd=update_occam_copper_access_profile';
	url=url+'&profile_id='+profile_id;
        url=url+'&name='+escape(name);
        url=url+'&description='+escape(description);
        url=url+'&sid='+Math.random();
        
        //Send the data to the query.php script to update the DB
        var myRequest = new Request({
                url: url, 
                onSuccess: function(response) {
                                //alert(response);
                } 
        }).send();
}

function delete_occam_copper_access_profile(profile_id, name) {
	var answer = confirm("Are you sure you want to remove Access Profile:\n"+name);
	
	if (answer) { 
	        var url='pages/query.php?';
	        url=url+'&cmd=delete_occam_copper_access_profile';
		url=url+'&profile_id='+profile_id;
        	url=url+'&sid='+Math.random();
        	
        	//Send the data to the query.php script to update the DB
        	var myRequest = new Request({
        	        url: url, 
        	        onSuccess: function(response) {
        	        		//TODO:  Remove this entry from the list of results    
			        	//alert(response);
        	        } 
        	}).send();
	}
	else {
		//Do nothing
	}
}	

function add_occam_copper_dsl_profile(name) {
        var url='pages/query.php?';
        url=url+'&cmd=add_occam_copper_dsl_profile';
        url=url+'&name='+escape(name);
        url=url+'&sid='+Math.random();
        
        //Send the data to the query.php script to update the DB
        var myRequest = new Request({
                url: url, 
                onSuccess: function(response) {
                                //TODO:  Append the new profile to the results list
                                //alert(response);
                } 
        }).send();
}

function update_occam_copper_dsl_profile(profile_id, name) {
        var url='pages/query.php?';
        url=url+'&cmd=update_occam_copper_dsl_profile';
	url=url+'&profile_id='+profile_id;
        url=url+'&name='+escape(name);
        url=url+'&sid='+Math.random();
        
        //Send the data to the query.php script to update the DB
        var myRequest = new Request({
                url: url, 
                onSuccess: function(response) {
                                //alert(response);
                } 
        }).send();
	//document.getElementById("occam_copper_access_profile_results").innerHTML = html;
}

function delete_occam_copper_dsl_profile(profile_id, name) {
	var answer = confirm("Are you sure you want to remove:\n"+name);
	if (answer) {
	        var url='pages/query.php?';
	        url=url+'&cmd=delete_occam_copper_dsl_profile';
		url=url+'&profile_id='+profile_id;
        	url=url+'&sid='+Math.random();
        	
        	//Send the data to the query.php script to update the DB
        	var myRequest = new Request({
        	        url: url, 
        	        onSuccess: function(response) {
        	        		//TODO:  Remove this entry from the list of results    
			        	//alert(response);
        	        } 
        	}).send();
	}
	else {
		//Do Nothing
	}
}

function add_occam_fiber_ont_start_ip(blade_ip, ont_start_ip) {
        var url='pages/query.php?';
        url=url+'&cmd=add_occam_fiber_ont_start_ip';
        url=url+'&blade_ip='+blade_ip;
        url=url+'&ont_start_ip='+escape(ont_start_ip);
        url=url+'&sid='+Math.random();
        
        //Send the data to the query.php script to update the DB
        var myRequest = new Request({
                url: url, 
                onSuccess: function(response) {
                                //TODO:  Append the new profile to the results list
                                //alert(response);
                } 
        }).send();
}

function update_occam_ont_start_ip(blade_ip, ont_start_ip) {
        var url='pages/query.php?';
        url=url+'&cmd=update_occam_fiber_ont_start_ip';
        url=url+'&blade_ip='+blade_ip;
        url=url+'&ont_start_ip='+escape(ont_start_ip);
        url=url+'&sid='+Math.random();
        
        //Send the data to the query.php script to update the DB
        var myRequest = new Request({
                url: url, 
                onSuccess: function(response) {
                                //TODO:  Append the new profile to the results list
                                //alert(response);
                } 
        }).send();
}

function delete_table_row(table, primary_key_name, primary_key_value) {
	var answer = confirm("Are you sure you want to remove:\n"+primary_key_value);
	if (answer) {
        	var url='pages/query.php?';
        	url=url+'&cmd=delete_table_row';
        	url=url+'&table='+table;
        	url=url+'&primary_key_name='+primary_key_name;
        	url=url+'&primary_key_value='+primary_key_value;
        	url=url+'&sid='+Math.random();

        	//Send the data to the query.php script to update the DB
        	var myRequest = new Request({
        	        url: url, 
        	        onSuccess: function(response) {
        	                        //alert(response);
        	        } 
        	}).send();
	}
	else {
		//Do Nothing
	}
}

</script>
